<template>
        <el-dialog top="5%" :title="this.form.FTitle" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="110px">
                <el-form-item :label="dateTitle">
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.FCreateDate"  style="width: 100%"></el-date-picker>
                </el-form-item>
                <el-form-item label="客户名称"  prop="FCustID">
                    <sy-select v-model="form.FCustID" remote
                               optionData="server/customer/Customer.ashx?cmd=GetOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="项目名称"  prop="FProjectName">
                    <sy-select v-model="form.FProjectID"
                               :optionData="'server/customer/Project.ashx?cmd=GetOptions&FCustID='+(form.FCustID?form.FCustID:-1)">
                    </sy-select>
                </el-form-item>
                <el-form-item v-if="form.FType==3" label="合同编号">
                    <el-input  v-model="form.FContractNo"></el-input>
                </el-form-item>
                <el-form-item label="业务员">
                    <sy-select :disabled="true" v-model="form.FUserID"
                               optionData="server/system/User.ashx?cmd=GetUserOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="真实名字" v-if="names.length>1">
                    <el-radio-group v-model="form.FRealName">
                        <el-radio :label="names[0]"></el-radio>
                        <el-radio :label="names[1]"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="form.FNote"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button v-if="authEdit" type="primary" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
</template>

<script>
    import util from '../../common/util'
    export default {
        data() {
            return {
                authEdit:false,
                names:[],
                form: {},
                rules: {

                },
                loading:false,
                editFormVisible:false
            }
        },
        computed: {
            dateTitle: function () {
                let c = {
                    1:"新增日期",
                    2:"发合同日期",
                    3:"实际签合同日期"
                }
                return c[this.form.FType]
            }
        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record,authEdit) {
                this.authEdit = authEdit
                this.editFormVisible = true
                this.form = Object.assign({},record)
                //真实名字默认第一个
                if(this.form.UserRealName){
                    this.names = this.form.UserRealName.split(",")
                }
            },
            _openAdd(record) {
                this.authEdit = true
                this.editFormVisible = true
                let form = {FID:0,
                    FTitle:"",
                    FCreateDate:global.sysParam.ServerDate,
                    FToDate:null,
                    FLinkPhone:"",
                    FType:1,
                    FCustID:null,
                    FProjectID:null,
                    FUserID:global.user.FID
                }
                //真实名字默认第一个
                if(global.user.FRealName){
                    this.names = global.user.FRealName.split(",")
                    form.FRealName = this.names[0]
                }
                this.form = Object.assign(form,record)
            },
            save:function () {
                if(!this.form.FCustID){
                    util.msgWarning("请填写客户")
                    return
                }
                if(!this.form.FProjectID){
                    util.msgWarning("请填写项目")
                    return
                }
                if(this.form.FType==3 && !this.form.FContractNo){
                    util.msgWarning("请填写合同编号")
                    return
                }
                util.post("server/report/ReportTrace.ashx?cmd=Save",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc",this.form)
                })
            }
        }
    }
</script>
